#include "ActionTopic.h"
#include "1650_agentbackend.pb.h"


bool ActionTopic::Init()
{
    log_debug("enter");
    Ctx.msg_router.BindMsg(agentbackend::AGENT_BACKEND_MSG_ID_REFRESH_CONFIG, ActionTopic::OnPhpCfgUpdate);
    return true;
}

void ActionTopic::OnPhpCfgUpdate(MsgData&& msg_data)
{
    log_debug("enter");
    agentbackend::RefreshConfigNotify notify;

    do
	{
        if (!notify.ParseFromArray(msg_data.data.data(), msg_data.data.size()))
        {
            log_error("parser topic_proto::Topic failed");
            break;
        }
        // 只要有通知,表明对应缓存有变化,则清空缓存,等待重新加载
        for (int i = 0; i < notify.config_size(); i++)
        {
            auto& item = notify.config(i);
            Ctx.host->m_pGame->m_dbHandler.UpdatePhpCfg(item.configname());// 重新获取配置
        }
        Ctx.host->m_pGame->LoadCfgToMap();// 重新加载配置到内存
	}while(false);



}